/*
 * @Author: zxc
 * @Date: 2020-08-04 20:28:16
 * @LastEditTime: 2020-08-04 20:36:36
 * @LastEditors: zxc
 * @Description: es6的set
 */
const s1 = new Set()
s1.add('a')
s1.add('b')
s1.add('c')

const s2 = new Set()
s2.add('a')
s2.add('b')

const s3 = new Set()
s3.add('d')

// 并集
const uninon = (a,b) => {
  const s = new Set()
  a.forEach(e => s.add(e))
  b.forEach(e => s.add(e))
  return s
}

// 交集
const intersection = (a,b) => {
  const s = new Set()
  a.forEach(e => {
    if(b.has(e)){
      s.add(e)
    }
  })
  return s
}

// 差集
const difference = (a,b) => {
  const s = new Set()
  a.forEach(e => {
    if(!b.has(e)){
      s.add(e)
    }
  })
  return s
}

console.log(uninon(s1,s3))
console.log(intersection(s1,s2))
console.log(difference(s3,s1))